<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8" /> 
	<title>Study React</title>
	<script src="https://cdn.staticfile.org/react/16.4.0/umd/react.development.js"></script>
	<script src="https://cdn.staticfile.org/react-dom/16.4.0/umd/react-dom.development.js"></script>
	<script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
</head>

<body>
    总结起来：<br/>
    1. 非受控组件：现用现取；可以使用ref来实现；<br/>
    2. 受控组件：被state所管理 <br/>
    不过感觉挺麻烦 要写这么多代码呀
	<div id="example"></div>

	<script type="text/babel">
        class Demo extends React.Component {
            state = {
                inputValue: "",
                passwordValue: ""
            };

            changeInput = (e)=> {
                this.setState({inputValue: e.target.value});
            }

            changePsd = (e)=> {
                this.setState({passwordValue: e.target.value});
            }

            submitForm = (e)=> {
                // e.preventDefault();
                const {inputValue, passwordValue} = this.state;
                alert(`用户名：${inputValue}, 密码：${passwordValue}`);
            }

            render() {
                const {inputValue, passwordValue} = this.state;
                return (
                    <form onSubmit={this.submitForm}>
                        用户名：<input type="text" value={inputValue} onChange={this.changeInput} />
                        密码: <input type="password" value={passwordValue} onChange={this.changePsd}/>
                        <button>submit</button>
                    </form>
                );
            }
        }
        
		ReactDOM.render(<Demo />, document.getElementById('example'));
	</script>

</body>

</html>